;; 多层次测试continuation返回值
(display "多层次测试continuation返回值\n")

;; 1. 简单的call/cc调用
(display "测试1: 简单的call/cc调用\n")
(display "直接结果: ")
(display (call/cc (lambda (k) (k 42))))
(display "\n\n")

;; 2. 使用define捕获
(display "测试2: 使用define捕获continuation返回值\n")
(define result (call/cc (lambda (k) (k 42))))
(display "define后的结果: ")
(display result)
(display "\n\n")

;; 3. 在函数中使用call/cc
(display "测试3: 在函数中使用call/cc\n")
(define get-cc-value 
  (lambda () 
    (call/cc (lambda (k) (k 42)))))
(display "函数调用结果: ")
(display (get-cc-value))
(display "\n\n")

;; 4. 嵌套调用
(display "测试4: 嵌套调用\n")
(define inner-func 
  (lambda () 
    (display "进入inner-func\n")
    (call/cc (lambda (k) (k 42)))))

(define outer-func 
  (lambda () 
    (display "进入outer-func\n")
    (define v (inner-func))
    (display "outer-func收到值: ")
    (display v)
    (display "\n")
    v))

(display "嵌套调用结果: ")
(display (outer-func))
(display "\n\n")

(display "所有测试完成\n")